$(document).ready(function() {
	var emailreg = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
	  
	  var vars = [], hash;
      var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('#');
	    for(var i = 0; i < hashes.length; i++) {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
     var user=vars["user"];
     
	var map = $('#map').gmap().bind('init', function(evt, map) {
		$('#map').gmap('getCurrentPosition', function(position, status) {
			if ( status === 'OK' ) {
			var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
			$('#map').gmap('option', 'zoom', 8);
			$('#map').gmap('addMarker', {'position': clientPosition, 'bounds': true}).click(function() {
									$('#map').gmap('openInfoWindow', { content : "yo"}, this);
									});
				
			}
		});   
	});
			Parse.$= jQuery; 
		    //Parse.initialize("cIsgepqAZm90F2mWdiJ9nP5HkrdG3nBcs98yJrVA", "CYI3htcqoz9bERjSCTpqu5FOWjhkkl72CgEenoLD");	
		   Parse.initialize("UCyMTCIXJqmFk3oLy4CwkxXv6oymztzqqoQNWAux", "BBYPhajAwBgLFzDTXvnx4MaReUn8Kke2KkwQ4yTT");
		    //Parse.initialize("gLxhWhhBK7SPLZ7Jevs6q2lcLBlhje3l3sQlyS0e", "nPvJsuTXpFeKvNyDjZg8ks8sYwt2nntVOi9hr91J");
			var friends = Parse.Object.extend("Friends");
			var query = new Parse.Query(friends);
			query.equalTo("friend1", user);
			query.find({
				success: function(results){
					var s = "</br>";
					for(var i = 0, len = results.length; i<len; i++){
						var amigo = results[i];
						var flat = amigo.get("lat");
						var flng = amigo.get("lng");
						var friendPosition = new google.maps.LatLng(flat, flng);
						$('#map').gmap('addMarker', {'position': friendPosition }).click(function() {
									$('#map').gmap('openInfoWindow', { content : amigo.get("friend2") }, this);
									});
					 s += "<li><a href='#'>";
					 s += "<b>"+amigo.get("friend2")+" esta en "+friendPosition+"</b>";
					 s += "</a></li> ";
					}
					$(".posiami").append(s);
				}
			});
			
	
		$('#map').gmap('addShape', 'Circle', { 
				'strokeWeight': 0, 
				'fillColor': "#008595", 
				'fillOpacity': 0.25, 
				'center': clientPosition, 
				'radius': 15, 
				'clickable': true
				});
});
